home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Eudora 1.3.1 / source / modeless.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-16  |  3.0 KB  |  130 lines  |  [TEXT/MPS ]

  1. #define FILE_NUM 26
  2. /* Copyright (c) 1990-1992 by the University of Illinois Board of Trustees */
  3. #pragma load EUDORA_LOAD
  4. #pragma segment Util
  5.  
  6. /************************************************************************
  7.  * GetNewMyDialog - get a new dialog, with a bit extra
  8.  ************************************************************************/
  9. MyWindowPtr GetNewMyDialog(short template,UPtr wStorage,WindowPtr behind,
  10.     void (*centerFunction)())
  11. {
  12.     MyWindowPtr win;
  13.     
  14.     if (wStorage == nil)
  15.     {
  16.         if (HandyWindow)
  17.         {
  18.             wStorage = HandyWindow;
  19.             HandyWindow = nil;
  20.         }
  21.         else if ((wStorage=NuPtr(sizeof(MyWindow)))==nil)
  22.             return (nil);
  23.     }
  24.     WriteZero(wStorage, sizeof(MyWindow));
  25.     
  26.     (*centerFunction)(template);
  27.     win = GetNewDialog(template, wStorage, behind);
  28.     if (win==nil) return(nil);
  29.     win->isDialog = win->isRunt = True;
  30.     SetPort(win);
  31.     win->contR = ((GrafPtr)win)->portRect;
  32.     win->qWindow.refCon = CREATOR;
  33.     return(win);
  34. }
  35.  
  36. /************************************************************************
  37.  * DoModelessEvent - handle (the result of) an event in a modeless dialog
  38.  ************************************************************************/
  39. Boolean DoModelessEvent(EventRecord *event)
  40. {
  41.     long select;
  42.     Boolean result;
  43.     DialogPtr dlog = FrontWindow();
  44.     short item;
  45.     char key = event->message & charCodeMask;
  46.     
  47.     /*
  48.      * check for cmdkey equivalents
  49.      */
  50.     if (event->what==keyDown)
  51.     {
  52.         if (event->modifiers&cmdKey)
  53.         {
  54.             if (select=MyMenuKey(event))
  55.             {
  56.                 DoMenu(FrontWindow(),select,event->modifiers);
  57.                 result = 0;
  58.                 goto done;
  59.             }
  60.             else if (key=='.')
  61.             {
  62.                 result = (*((MyWindowPtr)dlog)->hit)(event,dlog,2);
  63.                 goto done;
  64.             }
  65.         }
  66.         else if (key==returnChar || key==enterChar)
  67.         {
  68.                 result = (*((MyWindowPtr)dlog)->hit)(event,dlog,1);
  69.                 goto done;
  70.         }
  71.     }
  72.  
  73.     /*
  74.      * do the event
  75.      */
  76.     result = DialogSelect(event,&dlog,&item) ?
  77.         (*((MyWindowPtr)dlog)->hit)(event,dlog,item) : False;
  78.     
  79.     /*
  80.      * if drawing, outline the ok button
  81.      */
  82.     if (event->what==updateEvt || event->what==activateEvt) HiliteButtonOne(dlog);
  83.     
  84.     if (event->what==app4Evt) SFWTC = True;
  85.  
  86. done:
  87.     EnableMenus(FrontWindow());
  88.     return(result);
  89. }
  90.  
  91. /************************************************************************
  92.  * DoModelessEdit - handle the Edit menu for a modeless dialog
  93.  ************************************************************************/
  94. Boolean DoModelessEdit(MyWindowPtr win,short item)
  95. {
  96.     short err;
  97.     switch(item)
  98.     {
  99.         case EDIT_CUT_ITEM:
  100.             DlgCut(win);
  101.             if ((err=ZeroScrap()) || (err=TEToScrap()))
  102.                 WarnUser(COPY_FAILED,err);
  103.             break;
  104.         case EDIT_COPY_ITEM:
  105.             DlgCopy(win);
  106.             if ((err=ZeroScrap()) || (err=TEToScrap()))
  107.                 WarnUser(COPY_FAILED,err);
  108.             break;
  109.         case EDIT_PASTE_ITEM:
  110.             if (InfoScrap()->scrapSize == 0)
  111.                 SysBeep(20);
  112.             else if (err=TEFromScrap())
  113.                 WarnUser(PASTE_FAILED,err);
  114.             else
  115.                 DlgPaste(win);
  116.             break;
  117.         case EDIT_CLEAR_ITEM:
  118.             DlgDelete(win);
  119.             break;
  120.         case EDIT_SELECT_ITEM:
  121.             SelIText(win,((DialogPeek)win)->editField+1,0,INFINITY);
  122.             break;
  123.         case EDIT_UNDO_ITEM:
  124.             break;
  125.         default:
  126.             return(False);
  127.     }
  128.     return(True);
  129. }
  130.